home *** CD-ROM | disk | FTP | other *** search
/ Windows Game Programming for Dummies (2nd Edition) / WinGamProgFD.iso / pc / DirectX SDK / DXSDK / samples / Multimedia / VBSamples / DirectShow / Editing / TrimmerVB / modGeneral.bas < prev    next >
Encoding:
BASIC Source File  |  2001-10-08  |  20.5 KB  |  412 lines

  1. Attribute VB_Name = "modGeneral"
  2. '*******************************************************************************
  3. '*       This is a part of the Microsoft DXSDK Code Samples.
  4. '*       Copyright (C) 1999-2001 Microsoft Corporation.
  5. '*       All rights reserved.
  6. '*       This source code is only intended as a supplement to
  7. '*       Microsoft Development Tools and/or SDK documentation.
  8. '*       See these sources for detailed information regarding the
  9. '*       Microsoft samples programs.
  10. '*******************************************************************************
  11. Option Explicit
  12. Option Base 0
  13. Option Compare Text
  14.  
  15.  
  16.  
  17. ' **************************************************************************************************************************************
  18. ' * PUBLIC INTERFACE- WIN32 API CONSTANTS
  19. ' *
  20. ' *
  21.             Public Const FO_COPY = &H2
  22.             Public Const FO_DELETE = &H3
  23.             Public Const FO_MOVE = &H1
  24.             Public Const FO_RENAME = &H4
  25.             Public Const FOF_ALLOWUNDO = &H40
  26.             Public Const FOF_CONFIRMMOUSE = &H2
  27.             Public Const FOF_FILESONLY = &H80      ''"" on *.*, do only files
  28.             Public Const FOF_MULTIDESTFILES = &H1
  29.             Public Const FOF_NOCONFIRMATION = &H10      ''"" Don't prompt the user.
  30.             Public Const FOF_NOCONFIRMMKDIR = &H200     ''"" don't confirm making any needed dirs
  31.             Public Const FOF_NOCOPYSECURITYATTRIBS = &H800     ''"" dont copy NT file Security Attributes
  32.             Public Const FOF_NOERRORUI = &H400     ''"" don't put up error UI
  33.             Public Const FOF_NORECURSION = &H1000    ''"" don't recurse into directories.
  34.             Public Const FOF_NO_CONNECTED_ELEMENTS = &H2000    ''"" don't operate on connected file elements.
  35.             Public Const FOF_RENAMEONCOLLISION = &H8
  36.             Public Const FOF_SILENT = &H4       ''"" don't create progress"report
  37.             Public Const FOF_SIMPLEPROGRESS = &H100     ''"" means don't show names of files
  38.             Public Const FOF_WANTMAPPINGHANDLE = &H20      ''"" Fill in SHFILEOPSTRUCT.hNameMappings
  39.             Private Const MAX_PATH As Long = 255
  40.             Private Const INVALID_HANDLE_VALUE = -1
  41.             Private Const SEM_FAILCRITICALERRORS = &H1
  42.             Private Const SEM_NOOPENFILEERRORBOX = &H8000
  43.             Private Const SEE_MASK_CLASSKEY = &H3
  44.             Private Const SEE_MASK_CLASSNAME = &H1
  45.             Private Const SEE_MASK_CONNECTNETDRV = &H80
  46.             Private Const SEE_MASK_DOENVSUBST = &H200
  47.             Private Const SEE_MASK_FLAG_DDEWAIT = &H100
  48.             Private Const SEE_MASK_FLAG_NO_UI = &H400
  49.             Private Const SEE_MASK_HOTKEY = &H20
  50.             Private Const SEE_MASK_ICON = &H10
  51.             Private Const SEE_MASK_IDLIST = &H4
  52.             Private Const SEE_MASK_INVOKEIDLIST = &HC
  53.             Private Const SEE_MASK_NOCLOSEPROCESS = &H40
  54.  
  55. ' **************************************************************************************************************************************
  56. ' * PUBLIC INTERFACE- WIN32 API DATA STRUCTURES
  57. ' *
  58. ' *
  59.             Private Type FILETIME
  60.                     dwLowDateTime As Long
  61.                     dwHighDateTime As Long
  62.             End Type
  63.             
  64.             Public Type WIN32_FIND_DATA
  65.                     dwFileAttributes As Long
  66.                     ftCreationTime As FILETIME
  67.                     ftLastAccessTime As FILETIME
  68.                     ftLastWriteTime As FILETIME
  69.                     nFileSizeHigh As Long
  70.                     nFileSizeLow As Long
  71.                     dwReserved0 As Long
  72.                     dwReserved1 As Long
  73.                     cFileName As String * MAX_PATH
  74.                     cAlternate As String * 14
  75.             End Type
  76.             
  77.             Private Type SHFILEOPSTRUCT
  78.                     hWnd As Long
  79.                     wFunc As Long
  80.                     pFrom As String
  81.                     pTo As String
  82.                     fFlags As Integer
  83.                     fAnyOperationsAborted As Long
  84.                     hNameMappings As Long
  85.                     lpszProgressTitle As String '  only used if FOF_SIMPLEPROGRESS
  86.             End Type
  87.             
  88.             Private Type SHELLEXECUTEINFO
  89.                     cbSize As Long
  90.                     fMask As Long
  91.                     hWnd As Long
  92.                     lpVerb As String
  93.                     lpFile As String
  94.                     lpParameters As String
  95.                     lpDirectory As String
  96.                     nShow As Long
  97.                     hInstApp As Long
  98.                     '  Optional fields
  99.                     lpIdList As Long
  100.                     lpClass As String
  101.                     hkeyClass As Long
  102.                     dwHotKey As Long
  103.                     hIcon As Long
  104.                     hProcess As Long
  105.             End Type
  106.  
  107.  
  108. ' **************************************************************************************************************************************
  109. ' * PUBLIC INTERFACE- WIN32 API DECLARATIONS
  110. ' *
  111. ' *
  112.             Private Declare Function FindClose Lib "kernel32" (ByVal hFindFile As Long) As Long
  113.             Private Declare Function SetErrorMode Lib "kernel32" (ByVal wMode As Long) As Long
  114.             Private Declare Function ShellExecuteEx Lib "shell32" (lpExecInfo As SHELLEXECUTEINFO) As Long
  115.             Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long
  116.             Private Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" (ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long
  117.             Private Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
  118.  
  119.  
  120.  
  121.  
  122.  
  123. ' **************************************************************************************************************************************
  124. ' * PUBLIC INTERFACE- DEXTER PROCEDURES
  125. ' *
  126. ' *
  127.             ' ******************************************************************************************************************************
  128.             ' * procedure name: GetPinInfo
  129.             ' * procedure description:  Returns an IPinInfo interface given a filtergraph manager and IPin object.
  130.             ' *                                       The derived IPinInfo interface can be utilized for gaining information on the elected pin.
  131.             ' ******************************************************************************************************************************
  132.             Public Function GetPinInfo(objFilterGraphManager As FilgraphManager, objPin As IPin) As IPinInfo
  133.             Dim objPin2 As IPin
  134.             Dim objPinInfo As IPinInfo
  135.             Dim objFilterInfo As IFilterInfo
  136.             Dim objPinCollection As Object
  137.             Dim objlFilterCollection As Object
  138.             On Local Error GoTo ErrLine
  139.             
  140.             'derive a filter collection from the filtergraph manager
  141.             Set objlFilterCollection = objFilterGraphManager.FilterCollection
  142.             
  143.             'enumerate through the filter(s) in the collection
  144.             For Each objFilterInfo In objlFilterCollection
  145.                 Set objPinCollection = objFilterInfo.Pins
  146.                 For Each objPinInfo In objPinCollection
  147.                     Set objPin2 = objPinInfo.Pin
  148.                     If objPin2 Is objPin Then
  149.                         Set GetPinInfo = objPinInfo
  150.                         Exit Function
  151.                     End If
  152.                 Next
  153.             Next
  154.             
  155.             'clean-up & dereference
  156.             If Not objPin2 Is Nothing Then Set objPin2 = Nothing
  157.             If Not objPinInfo Is Nothing Then Set objPinInfo = Nothing
  158.             If Not objFilterInfo Is Nothing Then Set objFilterInfo = Nothing
  159.             If Not objPinCollection Is Nothing Then Set objPinCollection = Nothing
  160.             If Not objlFilterCollection Is Nothing Then Set objlFilterCollection = Nothing
  161.             Exit Function
  162.             
  163. ErrLine:
  164.             Err.Clear
  165.             Exit Function
  166.             End Function
  167.             
  168.             
  169.             ' ******************************************************************************************************************************
  170.             ' * procedure name: AddFileWriterAndMux
  171.             ' * procedure description:  Appends a filewriter and mux filter to the given filtergraph.
  172.             ' *                                       The FileName as required for the filewriter and evaluates to the output file destination.
  173.             ' ******************************************************************************************************************************
  174.             Public Sub AddFileWriterAndMux(objFilterGraphManager As FilgraphManager, bstrFileName As String)
  175.             Dim objFilterInfo As IFilterInfo
  176.             Dim objRegisteredFilters As Object
  177.             Dim objAVIMuxFilterInfo As IFilterInfo
  178.             Dim objRegFilterInfo As IRegFilterInfo
  179.             Dim objFileSinkFilterVB As IFileSinkFilterForVB
  180.             On Local Error GoTo ErrLine
  181.             
  182.             'derive a collection of registered filters from the filtergraph manager
  183.             Set objRegisteredFilters = objFilterGraphManager.RegFilterCollection
  184.             
  185.             'enumerate through the registered filters
  186.             For Each objRegFilterInfo In objRegisteredFilters
  187.                 If Trim(LCase(objRegFilterInfo.Name)) = "file writer" Then
  188.                     objRegFilterInfo.Filter objFilterInfo
  189.                 ElseIf Trim(LCase(objRegFilterInfo.Name)) = "avi mux" Then
  190.                     objRegFilterInfo.Filter objAVIMuxFilterInfo
  191.                 End If
  192.             Next
  193.             
  194.             'derive the file sink filter tailored for vb
  195.             Set objFileSinkFilterVB = objFilterInfo.Filter
  196.             'assign the filename to the sink filter
  197.             Call objFileSinkFilterVB.SetFileName(bstrFileName, Nothing)
  198.             
  199.             'clean-up & dereference
  200.             If Not objFilterInfo Is Nothing Then Set objFilterInfo = Nothing
  201.             If Not objRegFilterInfo Is Nothing Then Set objRegFilterInfo = Nothing
  202.             If Not objFileSinkFilterVB Is Nothing Then Set objFileSinkFilterVB = Nothing
  203.             If Not objAVIMuxFilterInfo Is Nothing Then Set objAVIMuxFilterInfo = Nothing
  204.             If Not objRegisteredFilters Is Nothing Then Set objRegisteredFilters = Nothing
  205.             Exit Sub
  206.             
  207. ErrLine:
  208.             Err.Clear
  209.             Exit Sub
  210.             End Sub
  211.             
  212.             
  213.             ' ******************************************************************************************************************************
  214.             ' * procedure name: RenderGroupPins
  215.             ' * procedure description:  Renders the Pins out for the given timeline using the given render engine.
  216.             ' *
  217.             ' ******************************************************************************************************************************
  218.             Public Sub RenderGroupPins(objRenderEngine As RenderEngine, objTimeline As AMTimeline)
  219.             Dim objPin As IPin
  220.             Dim nCount As Long
  221.             Dim nGroupCount As Long
  222.             Dim objPinInfo As IPinInfo
  223.             Dim objFilterGraphManager As FilgraphManager
  224.             On Local Error GoTo ErrLine
  225.             
  226.             If Not objTimeline Is Nothing Then
  227.                If Not objRenderEngine Is Nothing Then
  228.                   'obtain the group count
  229.                   objTimeline.GetGroupCount nGroupCount
  230.                   'exit the procedure if there are no group(s)
  231.                   If nGroupCount = 0 Then Exit Sub
  232.                   'obtain the filtergraph
  233.                   objRenderEngine.GetFilterGraph objFilterGraphManager
  234.                   'enumerate through the groups & render the pins
  235.                    For nCount = 0 To nGroupCount - 1
  236.                        objRenderEngine.GetGroupOutputPin nCount, objPin
  237.                        If Not objPin Is Nothing Then
  238.                            Set objPinInfo = GetPinInfo(objFilterGraphManager, objPin)
  239.                            If Not objPinInfo Is Nothing Then
  240.                                Call objPinInfo.Render
  241.                            End If
  242.                        End If
  243.                    Next
  244.                End If
  245.             End If
  246.             Exit Sub
  247.             
  248. ErrLine:
  249.             Err.Clear
  250.             Resume Next
  251.             Exit Sub
  252.             End Sub
  253.             
  254.             
  255.             
  256. ' **************************************************************************************************************************************
  257. ' * PUBLIC INTERFACE- GENERAL PROCEDURES
  258. ' *
  259. ' *
  260.             ' ******************************************************************************************************************************
  261.             ' * procedure name: Buffer_ParseEx
  262.             ' * procedure description:   Parse's a fixed length string buffer of all vbNullCharacters AND vbNullStrings.
  263.             ' *                                        Argument bstrBuffer evaluates to either an ANSII or Unicode BSTR string buffer.
  264.             ' *                                        (bstrBuffer is almost always the output from a windows api call which needs parsed)
  265.             ' *
  266.             ' ******************************************************************************************************************************
  267.             Public Function Buffer_ParseEx(bstrBuffer As String) As String
  268.             Dim iCount As Long, bstrChar As String, bstrReturn As String
  269.             On Local Error GoTo ErrLine
  270.             
  271.             For iCount = 1 To Len(bstrBuffer) 'set up a loop to remove the vbNullChar's from the buffer.
  272.                   bstrChar = Strings.Mid(bstrBuffer, iCount, 1)
  273.                   If bstrChar <> vbNullChar And bstrChar <> vbNullString Then bstrReturn = (bstrReturn + bstrChar)
  274.             Next
  275.             Buffer_ParseEx = bstrReturn
  276.             Exit Function
  277.             
  278. ErrLine:
  279.             Err.Clear
  280.             Exit Function
  281.             End Function
  282.             
  283.             
  284.             ' ******************************************************************************************************************************
  285.             ' * procedure name: GetTempDirectory
  286.             ' * procedure description:  Returns a bstr String representing the fully qualified path to the system's temp directory
  287.             ' *
  288.             ' ******************************************************************************************************************************
  289.             Public Function GetTempDirectory() As String
  290.             Dim bstrBuffer As String * MAX_PATH
  291.             On Local Error GoTo ErrLine
  292.             
  293.             'call the win32api
  294.             Call GetTempPath(MAX_PATH, bstrBuffer)
  295.             'parse & return the value to the client
  296.             GetTempDirectory = Buffer_ParseEx(bstrBuffer)
  297.             Exit Function
  298.             
  299. ErrLine:
  300.             Err.Clear
  301.             Exit Function
  302.             End Function
  303.             
  304.             
  305.             
  306.             ' ******************************************************************************************************************************
  307.             ' * procedure name: File_Exists
  308.             ' * procedure description:  Returns true if the specified file does in fact exist.
  309.             ' *
  310.             ' ******************************************************************************************************************************
  311.             Public Function File_Exists(bstrFileName As String) As Boolean
  312.             Dim WFD As WIN32_FIND_DATA, hFile As Long
  313.             On Local Error GoTo ErrLine
  314.             
  315.             hFile = FindFirstFile(bstrFileName, WFD)
  316.             File_Exists = hFile <> INVALID_HANDLE_VALUE
  317.             Call FindClose(hFile)
  318.             Exit Function
  319.             
  320. ErrLine:
  321.             Err.Clear
  322.             Exit Function
  323.             End Function
  324.             
  325.             
  326.             ' ******************************************************************************************************************************
  327.             ' * procedure name: File_Delete
  328.             ' * procedure description:  This will delete a File. Pass any of the specified optionals to invoke those particular features.
  329.             ' *
  330.             ' ******************************************************************************************************************************
  331.             Public Function File_Delete(bstrFileName As String, Optional SendToRecycleBin As Boolean = True, Optional Confirm As Boolean = True, Optional ShowProgress As Boolean = True) As Long
  332.             Dim fileop As SHFILEOPSTRUCT
  333.             Dim WFD As WIN32_FIND_DATA, hFile As Long
  334.             On Local Error GoTo ErrLine
  335.             
  336.             'check argument
  337.             If Right(bstrFileName, 1) = "\" Then bstrFileName = Left(bstrFileName, (Len(bstrFileName) - 1))
  338.             'ensure the file exists
  339.             hFile = FindFirstFile(bstrFileName, WFD)
  340.             If hFile = INVALID_HANDLE_VALUE Then
  341.                Call FindClose(hFile)
  342.                Exit Function
  343.             Else: Call FindClose(hFile)
  344.             End If
  345.             'set the error mode
  346.             Call SetErrorMode(SEM_NOOPENFILEERRORBOX + SEM_FAILCRITICALERRORS)
  347.             'set up the file operation by the specified optionals
  348.             With fileop
  349.                 .hWnd = 0: .wFunc = FO_DELETE
  350.                 .pFrom = UCase(bstrFileName) & vbNullChar & vbNullChar
  351.                 If SendToRecycleBin Then   'goes to recycle bin
  352.                    .fFlags = FOF_ALLOWUNDO
  353.                    If Confirm = False Then .fFlags = .fFlags + FOF_NOCONFIRMATION  'do not confirm
  354.                    If ShowProgress = False Then .fFlags = .fFlags + FOF_SILENT  'do not show progress
  355.                 Else 'just delete the file
  356.                    If Confirm = False Then .fFlags = .fFlags + FOF_NOCONFIRMATION  'do not confirm
  357.                    If ShowProgress = False Then .fFlags = .fFlags + FOF_SILENT  'do not show progress
  358.                 End If
  359.             End With
  360.             'execute the file operation, return any errors..
  361.             File_Delete = SHFileOperation(fileop)
  362.             Exit Function
  363.             
  364. ErrLine:
  365.             File_Delete = Err.Number  'if there was a abend in the procedure, return that too..
  366.             Err.Clear
  367.             Exit Function
  368.             End Function
  369.             
  370.             
  371.             ' ******************************************************************************************************************************
  372.             ' * procedure name: File_Execute
  373.             ' * procedure description:  Executes a file using it's default shell command and returns a handle to the new process.
  374.             ' *                                       Function returns zero if the operation fails.  Never displays any error dialogs for the user.
  375.             ' *
  376.             ' ******************************************************************************************************************************
  377.             Public Function File_Execute(bstrDirectory As String, bstrFile As String, Optional bstrArguments As String, Optional Show As Long = 1) As Long
  378.             Dim ExecInfo As SHELLEXECUTEINFO
  379.             On Local Error GoTo ErrLine
  380.             
  381.             'verify argument(s)
  382.             If Len(bstrDirectory) > 0 Then
  383.                If Right(bstrDirectory, 1) = "\" Then
  384.                   bstrDirectory = Trim(LCase(Mid(bstrDirectory, 1, Len(bstrDirectory) - 1)))
  385.                End If
  386.             ElseIf Len(bstrFile) > 0 Then
  387.                If Right(bstrFile, 1) = "\" Then
  388.                   bstrFile = Trim(LCase(Mid(bstrFile, 1, Len(bstrFile) - 1)))
  389.                End If
  390.             End If
  391.             
  392.             'fill data struct
  393.             With ExecInfo
  394.             .nShow = 1
  395.             .cbSize = Len(ExecInfo)
  396.             .lpFile = bstrFile
  397.             .lpDirectory = bstrDirectory
  398.             .lpParameters = bstrArguments
  399.             .fMask = SEE_MASK_FLAG_NO_UI + SEE_MASK_DOENVSUBST + SEE_MASK_NOCLOSEPROCESS '+ CREATE_NEW_CONSOLE
  400.             End With
  401.             
  402.             'execute the application
  403.             Call ShellExecuteEx(ExecInfo)
  404.             'return the process id to the client
  405.             File_Execute = ExecInfo.hProcess
  406.             Exit Function
  407.             
  408. ErrLine:
  409.             Err.Clear
  410.             Exit Function
  411.             End Function
  412.